﻿
Partial Class Paginas_CombosGenIngreso
    Inherits System.Web.UI.Page
    Dim myForm As String = "Form1"
    Dim T_tabla As String = "CombosValores"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Introducir aquí el código de usuario para inicializar la página
        If Page.IsPostBack = False Then
            Session("llamador") = Request.UrlReferrer.ToString()
            Imprimir.Attributes.Add("onclick", "print();")
            borrar.Attributes.Add("onclick", "if (!confirm('Elimina Registro?')) return false")


            ' *****************   CARGA COMBO CON LOS GRUPOS **********************

            Dim ACCION As String = Request.QueryString("ACCION")
            Dim resultado As New DataSet
            Dim Rutinas As New DataServices.Rutinas

            Cestado.Checked = True

            ' **********  cargar Valores de la Llave  **********************

            If ACCION <> "0" Then
                borrar.Visible = True
                Dim VALORES() As String = Request.QueryString("Col0").Split(";")
                NCODIGO_PKI.Text = VALORES(0)
                TNOMBRE.Text = VALORES(1)

                Dim Csql = " Select *  from " & T_tabla & Rutinas.Clave_pagina(sender, e, Page, myForm, ACCION)

                resultado = Rutinas.ExtraeSql(Csql)
                If Csql <> "" Then
                    Call Rutinas.Carga_pagina(resultado.Tables(0), sender, e, Page, myForm)
                End If
            Else
                TNOMBRE.Text = Request.QueryString("nombre")
            End If

            'Call Rutinas.Valida_Acceso(sender, e, Page, "Form1", Session("accesos"))

        End If
    End Sub

    Private Sub Aceptar_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Aceptar.Click
        Dim resultado As New DataSet
        Dim Rutinas As New DataServices.Rutinas
        Dim strscript As String
        Dim csql As String

        If Trim(TDESCRIPCION.Text) = "" Then
            strscript = "<script>"
            strscript = strscript & "alert('Debe ingresar Descripción');"
            strscript = strscript & "</script>"
            Page.RegisterStartupScript("ClientScript", strscript)
            Exit Sub
        End If


        csql = "if exists( select * from " & T_tabla & Rutinas.Clave_pagina(sender, e, Page, myForm, "0") & " ) "
        csql = csql & Rutinas.Update_Sql(sender, e, Page, myForm, T_tabla)
        csql = csql & " Else " & Rutinas.Insert_Sql(sender, e, Page, myForm, T_tabla)

        Rutinas.EjecutarSql(csql)

        Try
            If csql <> "" Then
                Dim destino As String
                destino = "alert('Registro Actualizado');"
                'destino = destino & "document.location.href='" & Session("llamador") & "';"
                Dim scriptblock1 As String = "<script language='javascript'>" & destino & "</script>"
                Page.RegisterStartupScript("Launch_Report_Window", scriptblock1)
            End If
        Catch ex As Exception

        End Try


    End Sub

    Private Sub Salir_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Salir.Click
        Response.Redirect(Session("llamador"))
    End Sub

    Private Sub borrar_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles borrar.Click
        Dim resultado As New DataSet
        Dim Rutinas As New DataServices.Rutinas
        Dim csql As String

        csql = " Update " & T_tabla & " Set Cestado=0 " & Rutinas.Clave_pagina(sender, e, Page, myForm, "1")

        Rutinas.EjecutarSql(csql)
        Try
            If csql <> "" Then
                Dim destino As String
                destino = "alert('Registro Eliminado');"
                'destino = destino & "document.location.href='" & Session("llamador") & "';"
                Dim scriptblock1 As String = "<script language='javascript'>" & destino & "</script>"
                Page.RegisterStartupScript("Launch_Report_Window", scriptblock1)
            End If
        Catch ex As Exception

        End Try

    End Sub
End Class
